<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    姓: <input type="text" placeholder="姓" v-model="firstName">
    名: <input type="text" placeholder="名" v-model="lastName">
    全称: <input type="text" placeholder="全称" :value="fullName">

    <div>{{ address }}</div>
    <button @click="address.city = '绵阳'">修改城市</button>
  </div>

  <script src="./lib/vue.global.js"></script>
  <script>
    Vue.createApp({
      data() {
        return {
          firstName: '张',
          lastName: '三',
          fullName: '',
          address: {
            province: '四川',
            city: '成都',
          }
        }
      },
      // 侦听器
      watch: {
        // 简写
        firstName(newValue, oldValue) {
          console.log('firstName 变化了:', oldValue, ' --> ', newValue)
          this.fullName = newValue + this.lastName
        },
        // 全写
        lastName: {
          // 处理器，用于处理数据变化时的业务逻辑
          handler(newValue, oldValue) {
            console.log('lastname 变化了:', oldValue, ' --> ', newValue)
            this.fullName = this.firstName + newValue
          },
          // 立即调用
          immediate: true,
        },

        address: {
          handler() {
            console.log('地址变化了...')
          },
          // 深度监听，监听对当前对象及后代属性的修改
          deep: true,
        }
      },
    }).mount('#app')
  </script>
</body>
</html>